package Thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 杜伟毅
 * @version 1.0
 * @since 2024/08/25
 * 自行构造线程池练习
 */
public class MyExecutorsTest {
    public static void main(String[] args) {
        ExecutorService executorService = new ThreadPoolExecutor(5, 10,
                60L, TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(50),
                new MyThreadFactory(),
                /**
                 * 可以用默认的异常处理方法
                 */
                //new ThreadPoolExecutor.AbortPolicy(),

                /**
                 * 也可以自定义
                 */
                (r, executor) -> {
                    System.out.println("线程满了，处理不了了");
                });

        for (int i = 0; i < 300; i++) {
            ThreadUtils .sleep(10000);
            executorService.submit(() -> {
                ThreadUtils .sleep(10000);
                System.out.println("-----------------");
            });
        }

        executorService.shutdown();
    }
}
